package com.rabc.web.controller;

import com.utils.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "mock数据")
@RequestMapping("/mock")
public class MockController {

    @GetMapping("/article/list")
   public R articleList(){
       return R.success(generateProjectListData());
   }
   @PostMapping("/article/sort")
   public R sort(){
      return R.success("排名重设成功");
   };
    public static Map<String, Object> generateProjectListData() {
        Map<String, Object> response = new HashMap<>();
        response.put("total", 20);
        response.put("page", 1);
        response.put("size", 10);

        List<Map<String, Object>> list = new ArrayList<>();

        list.add(createProjectItem("612a198d218e733440da07e6", 1, "ESLint + Git Hooks", "Sunday", "1629099597000", "编码规范"));
        list.add(createProjectItem("612a198d218e733440da07ec", 2, "Tags View", "Sunday", "1629099597000", "便签快捷导航功能"));
        list.add(createProjectItem("612a198d218e733440da07e4", 3, "Element-Plus", "Sunday", "1629099597000", "基于 Vue 3.0 的桌面端组件库"));
        list.add(createProjectItem("612a198d218e733440da07ea", 4, "侧边栏", "Sunday", "1629099597000", "根据路由动态生成的 Menu 菜单"));
        list.add(createProjectItem("612a198d218e733440da07eb", 5, "动态面包屑", "Sunday", "1629099597000", "动态生成的面包屑数据"));
        list.add(createProjectItem("612a198d218e733440da07e8", 6, "权限验证", "Sunday", "1629099597000", "页面权限、功能权限、动态权限、权限配置"));
        list.add(createProjectItem("612a198d218e733440da07e5", 7, "vue-element-admin", "Sunday", "1629099597000", "后台前端解决方案"));
        list.add(createProjectItem("612a198d218e733440da07e3", 8, "Vue3 + 全家桶", "Sunday", "1629099597000", "项目基于最新的vue3全家桶进行开发"));
        list.add(createProjectItem("612a198d218e733440da07e9", 9, "功能引导", "Sunday", "1629099597000", "对用户的功能引导"));
        list.add(createProjectItem("612a198d218e733440da07e7", 10, "架构设计", "Sunday", "1629099597000", "架构设计"));

        response.put("list", list);

        return response;
    }




    private static Map<String, Object> createProjectItem(String id, int ranking, String title, String author, String publicDate, String desc) {
        Map<String, Object> item = new HashMap<>();
        item.put("_id", id);
        item.put("ranking", ranking);
        item.put("title", title);
        item.put("author", author);
        item.put("publicDate", publicDate);
        item.put("desc", desc);
        return item;
    }
}
